home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / pascal / bp70lib.zip / GRAF.DOC < prev    next >
Text File  |  1993-04-15  |  14KB  |  316 lines

  1. unit graf;
  2.  
  3. interface
  4.  
  5.  
  6. uses graph,crt,dos,generic,graf3;
  7.  
  8.  
  9.  
  10. type imgrec=record
  11.             p:pointer;
  12.             size:longint;
  13.             end;
  14.  
  15.      pointarray=array[1..10] of pointtype;
  16.  
  17.      poly=record
  18.           pt:pointarray;
  19.           size:integer;
  20.           end;
  21.  
  22.  
  23.  
  24.  
  25.  
  26. { NOTE: 1. all coords for routines are in video device independant
  27.            graf coords (0-1000 by 0-1000).
  28.         2. all areas are given by coords of UL and LR corners.
  29.         3. all drawing routines are graphics, not text.
  30.         4. vid coords are video device dependant (ega coords, vga coords,
  31.            etc).
  32.         5. on PCs, the mouse uses vid coords in graphics mode (in vidmodes
  33.            up thru vga).
  34.         6. all message boxes, menus, etc. save and restore the screen behind
  35.            them automatically.
  36.         7. routines with a doclick boolean will make a click sound when a
  37.            mouse button is pressed or released if doclick is true.
  38.         8. menus and message boxes use the global array m in the generic
  39.            unit.                                                           }
  40.  
  41.  
  42.  
  43.  
  44.  
  45. {############################## conversions ##############################}
  46.  
  47. function y2vidy(y:integer):integer;
  48.                                { converts graf y to vid (ega, vga, etc) y }
  49. function x2vidx(x:integer):integer;
  50.                                { converts graf x to vid (ega, vga, etc) x }
  51. function mousey2y(y:integer):integer;
  52.                                     { converts mouse (or vid) y to graf y. }
  53. function mousex2x(x:integer):integer;
  54.                                     { converts mouse (or vid) x to graf x. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60. {################################# mouse ##################################}
  61.  
  62. procedure select(var x,y:integer; donobutton:boolean);
  63.           { shows mouse, waits for mouse click, hides mouse, returns x,y
  64.             coords of mouse click in graf coords. Automactically draws mouse
  65.             cursor for 800x600, 1024x768, and 1280x1024 vidmodes. }
  66. function gmx:integer;
  67.  { returns current mouse x in graf coords. works for hi res vid modes too. }
  68. function gmy:integer;
  69.  { returns current mouse y in graf coords. works for hi res vid modes too. }
  70. procedure startmouse;    { turns on mouse in hi res vid modes. }
  71. procedure movemouse;     { moves mouse in hi res vid modes. }
  72. procedure stopmouse;     { hides mouse in hi res vid modes. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. {############################ clearscreens ################################}
  81.  
  82. procedure clsstars;           { clears screen to black with stars }
  83. procedure clsgraf(color,fillstyle:integer);
  84.                                        { clears screen in color,fillstyle }
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. {################################# fills ###################################}
  93.  
  94. procedure fillstars(x1,y1,x2,y2:integer);
  95.                                     { fills an area with stars on black }
  96. procedure fillgraf(x1,y1,x2,y2,color,fillstyle:integer);
  97.                                           { fills area in color,fillstyle }
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. {################################ drawing #################################}
  106.  
  107. procedure grafpix(x,y,color:integer);
  108.              { sets pixel @ x,y (graf coords) to color }
  109. function getpix(x,y:integer):integer;
  110.              { returns color of pixel @ x,y (graf cooords) }
  111. procedure grafline(x1,y1,x2,y2,color,style,thickness:integer);
  112.           { draws line from x1,y1 to x2,y2 in color,style,thickness. line
  113.             style and thickness are as in graph unit.}
  114. procedure grafpie(x,y,sa,ea,r,fore,bak,style:integer);
  115.           { draws filled pieslice at x,y from sa to ea degrees, radius r, in
  116.             colors fore,bak. style is fillstyle. borders are solid thin
  117.             lines. }
  118. procedure grafcircle(x,y,r,fore,style,thickness:integer);
  119.           { draw a circle of style,thickness at x,y with radius r. fore is
  120.             circle color. }
  121. procedure grafbar(x1,y1,x2,y2,depth,fore,bak,style,thickness,fill:integer; top:boolean);
  122.           { draws a 3d wireframe bar with style,thickness in colors fore,bak
  123.             with fillpattern fill on the face. x1,y1,x2,y2 is face. depth is
  124.             depth of bar. if top=true then draws top of bar. }
  125. procedure grafbox(x1,y1,x2,y2,fore,bak,style,thickness,fill:integer);
  126.           { draws filled rectangle in area x1,y1,x2,y2. fore is border color.
  127.             bak is fill color. style is border linestyle. thickness is border
  128.             thickness. fill is fillstyle. }
  129. procedure grafquad(x1,y1,x2,y2,x3,y3,x4,y4,fore,bak,style,thickness,fill:longint; doedge:boolean);
  130.           { draws a filled quadrangle. x1 thru y4 are coords of 4 corners.
  131.             assumes edges from corners 1 to 2 to 3 to 4 to 1. fore, style,
  132.             and thickness are border color, linestyle, and line thickness.
  133.             bak and fill are background color and fillstyle. }
  134. procedure grafcube(x1,y1,x2,y2,depth,fore,bak,style,thickness,fill:integer);
  135.           { draws a 3d solid box. x1 thru y2 are face coords. depth is depth
  136.             of box. fore, style, and thicknes are edge color, linestyle and
  137.             line thickness. bak and fill are fill color and style. }
  138. procedure grafrect(x1,y1,x2,y2,fore,style,thickness:integer);
  139.           { draws unfilled rectangle in area x1,y1,x2,y2. fore is border
  140.             color. style is border linestyle. thickness is border
  141.             thickness. }
  142. procedure graftri(x1,y1,x2,y2,x3,y3,fore,bak,style,thickness,fill:integer);
  143.           { draws a filled triangle. x1 thru y3 are coords of 3 corners.
  144.             assumes edges from corners 1 to 2 to 3 to 1. fore, style,
  145.             and thickness are border color, linestyle, and line thickness.
  146.             bak and fill are fill color and fillstyle. }
  147. procedure panel(x1,y1,x2,y2,width,color:integer; pressed:boolean);
  148.           { draws a 3d beveled panel. x1 thru y2 are panel area. width is
  149.             bevel width. color is panel color. if shadow=true, draws shadow
  150.             for the panel. if pressed=true, draws panel pressed in instead of
  151.             sticking out. }
  152. procedure grafpoly(p:poly; fore,bak,style,thickness,fill:longint; doedge:boolean);
  153.           { draws a filled polygon. poly is list of corners.
  154.             assumes edges from one corner to the next, and from last corner
  155.             to the 1st. fore, style, and thickness are border color,
  156.             linestyle, and line thickness. bak and fill are background
  157.             color and fillstyle. }
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165. {################################### text #################################}
  166.  
  167. procedure saygraf(x,y,color,font,size,orientation,hjustify,vjustify,multx,
  168.                   divx,multy,divy:integer; s:string);
  169.           { draws text at x,y. color,font,size,orientation (horiz/vert), and
  170.             text justifications, are as in graph unit. mults and divs control
  171.             graph unit`s setusercharsize. set mults and divs to 1 for no
  172.             setusercharsize. }
  173. procedure saygraf3d(x,y,color,font,size,orientation,hjustify,vjustify,multx,
  174.                   divx,multy,divy:integer; s:string);
  175.           { as saygraf, does 3d text. }
  176.  
  177. function textwidthof(s:string; font,size,orientation,hjustify,vjustify,multx,
  178.                      divx,multy,divy:integer):integer;
  179.    { returns the width of a string in graf coords. all parameters are as in
  180.      saygraf. }
  181.  
  182.  
  183.  
  184.  
  185.  
  186. {################################ buttons ################################}
  187.  
  188. procedure btn(x,y,fore,bak:integer; s:string; pressed:boolean);
  189.      { draws a button at x,y in colors fore,bak with 3d text s on it.
  190.        if pressed=true, draws button pressed in instead of sticking out.
  191.        button is 150 wide and 50 tall. }
  192. procedure btn2(x,y,fore,bak:integer; s:string; pressed:boolean);
  193.      { draws a button at x,y in colors fore,bak with 3d text s on it.
  194.        if pressed=true, draws button pressed in instead of sticking out.
  195.        button is 100 wide and 50 tall. }
  196. procedure btn3(x,y,fore,bak:integer; s:string; pressed:boolean);
  197.      { draws a button at x,y in colors fore,bak with 3d text s on it.
  198.        if pressed=true, draws button pressed in instead of sticking out.
  199.        button is 50 wide and 50 tall. }
  200. function isbtn(x,y,bx,by:integer):boolean;
  201.      { returns true if x,y lies within the area of a btn at bx,by. }
  202. function isbtn2(x,y,bx,by:integer):boolean;
  203.      { returns true if x,y lies within the area of a btn2 at bx,by. }
  204. function isbtn3(x,y,bx,by:integer):boolean;
  205.      { returns true if x,y lies within the area of a btn3 at bx,by. }
  206.  
  207.  
  208. procedure pressbtn(x,y,fore,bak:integer; s:string; doclick:boolean);
  209. { draws a button pressed in, waits for no mouse button, draws button
  210.   unpressed. does click sounds if doclick is true.  }
  211.  
  212. procedure pressbtn2(x,y,fore,bak:integer; s:string; doclick:boolean);
  213.                     { as pressbtn but for btn2's }
  214. procedure pressbtn3(x,y,fore,bak:integer; s:string; doclick:boolean);
  215.                     { as pressbtn but for btn3's }
  216.  
  217.  
  218. {############################### gets & puts ###############################}
  219.  
  220. function grafget(x1,y1,x2,y2:integer; var p:pointer):longint;
  221.      { copies area of screen to memory. x1 thru y2 are area cooords.
  222.        allocates memory for image. copies image to memory. sets p to point
  223.        to image in memory. returns memory allocated (size of image). }
  224. procedure grafput(x1,y1,put:integer; p:pointer);
  225.      { copies image from memory to screen at x1,y1. put is a put method as in
  226.        graph unit putimage. p points to image in memory. }
  227. procedure grafnuke(var p:pointer; size:longint);
  228.      { deallocates an image in memory. p points to image. size is size of
  229.        image. }
  230. procedure grafsave(s:string; p:pointer; size:longint);
  231.   { saves image pointed to by p in file with name s. size is size of image }
  232. procedure grafload(s:string; var p:pointer; var size:longint);
  233.   { loads image in file S into memory. alloactes memory for image. sets P
  234.     to point to image. sets SIZE to size of image. }
  235. procedure getarea(x1,y1,x2,y2:integer);
  236. { allocates memory and saves area of screen to memory. must putarea before
  237.   you getarea again. }
  238. procedure putarea(x1,y1,x2,y2:integer);
  239. { restores area of screen from memory and deallocates memory. must getarea
  240.   first. x1,y1,x2,y2 are same as in getarea. }
  241.  
  242.  
  243.  
  244. {################################ viewports ##############################}
  245.  
  246. procedure grafport(x1,y1,x2,y2:integer; clip:boolean);
  247.           { sets viewport to an area. if clip=true, viweport will clip
  248.             things drawn in it. }
  249. procedure grafportoff;
  250.           { sets viewport to full screen }
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257. {############################## interface parts ###########################}
  258.  
  259. function popupmenu(x,y,i,fore,bak:integer; doclick:boolean):integer;
  260.    { x=-1 centers left to right. y=-1 centers top to bottom. does menu at
  261.      x,y in colors fore,bak. uses global array m from generic unit. i is # of
  262.      items in menu. m[0] is menu title. m[1] thru m[i] are menu options. }
  263. function getorientation(s:string; fore,bak:integer; doclick:boolean):integer;
  264.    { does a menu in colors fore,bak to get a text orientation from the user.
  265.      s is menu prompt. }
  266. function gettextsize(s:string; font,fore,bak,size:integer):integer;
  267.    { does a dialog box in colors fore,bak to get a text size from the user.
  268.      s is prompt. font is the font to get the size of. size is text size that
  269.      the dialog box starts at. }
  270. function getnum(s:string; fore,bak:integer; doclick:boolean):integer;
  271.     { does a popup numeric keypad in colors fore,bak to get an integer from
  272.       the user. s is prompt. }
  273. function getlnum(s:string; fore,bak:integer; doclick:boolean):longint;
  274.     { does a popup numeric keypad in colors fore,bak to get an longint from
  275.       the user. s is prompt. }
  276. function getfont(s:string; fore,bak:integer):integer;
  277.   { does a menu in colors fore,bak to get a font from the user. s is prompt.}
  278. function getfillstyle(s:string; fore,bak,fillcolor:integer):integer;
  279.   { does a menu in colors fore,bak,fillcolor to get a fillstyle from the user.
  280.     s is prompt. }
  281. function getcolor(x,y,fore,bak:integer; s:string; doclick:boolean):integer;
  282.   { does a menu at x,y in colors fore,bak to get a color from the user. s is
  283.     prompt. x=-1 for center horiz. y=-1 for center vert. returns -1 for
  284.     cancel. }
  285. procedure grafmsg(x,y,i,fore,bak:integer; doclick,dopause,doprint:boolean);
  286.    { does a message box at x,y in colors fore,bak. x=-1 for center horiz.
  287.      y=-1 for center vert. uses global array m. i is # of lines in message.
  288.      If dopause is true, adds "Press P to print or mouse button to
  289.      continue..." to message and waits for mouse button before disappearing.
  290.      pressing P prints message to PRN. If dopause is false, message doesnt
  291.      disappear, and control returns immediately to caller. If doprint is
  292.      true, message is printed to PRN instead of being displayed. }
  293. function getstring(s,s2:string; forecolor,bakcolor,curfore,curbak:integer):string;
  294.     { does a string edit box in colors forecolor,bakcolor to get a string
  295.       from the user. s is string that initially appears for editing. s2 is
  296.       prompt. curfore,curbak are cursor colors. }
  297. function getfile(s,filespec:string; fore,bak:integer; doclick:boolean):string;
  298.    { does a menu (file listing) in colors fore,bak to get a filename from the
  299.      user. s is prompt. filespec is the search filespec for file listing. }
  300. function getdir2(s,filespec:string; fore,bak:integer; doclick:boolean):string;
  301.    { does a menu (dir listing) in colors fore,bak to get a directory name
  302.      from the user. s is prompt. filespec is the search filespec for dir
  303.      listing. }
  304. function getdrive(s:string; fore,bak:integer; doclick:boolean):char;
  305.    { does a menu (drive listing) in colors fore,bak to get a drive letter
  306.      from the user. s is prompt.  }
  307.  
  308.  
  309.  
  310.  
  311.  
  312. implementation
  313.  
  314.  
  315.  
  316.